/** COPYRIGHT(C) 2008. Loc Phan. All Rights Reserved.
    A class that modify JButton into an customized button
    @author Loc Phan
    @version 1.01 2008-12-1
*/

package edu.sjsu.cs.phan.gui;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JTextField;

public class EarthquakeButton extends JButton
{
   /**Constructs a button
    * 
    * @param aTextfield Text Field that this button takes the information from
    */
   public EarthquakeButton(JTextField aTextfield)
   {
      super("Display");
      TextField = aTextfield;
      ActionListener listener = new ButtonListener();
      this.addActionListener(listener);
   }
   /**
    *   A listener class
    */
   class ButtonListener implements ActionListener
   {
      public void actionPerformed(ActionEvent e)
      {
         try
         {
            double magnitude = Double.parseDouble(TextField.getText());
            Earthquake quake = new Earthquake(magnitude);
            Label.setText(quake.getDescription());
         }
         catch(Exception e1)
         {
            Label.setText("Please enter a number.");
         }
      }
   }
   /**Label that need to be updated
    * 
    * @param aLabel Label
    */
   public void addLabel(JLabel aLabel)
   {
      Label = aLabel;
   }
   private JLabel Label;
   private JTextField TextField;
}
